// pages/ecergency/viewEvent/viewEvent.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      title:'',
      eventId:'',//任务ID
      id:'',//任务信息的ID

      //应急事件详情
      attentionItem:'',
      remark:'',
      actionList:[],
      imgList:[],
      bigImgList:[],
      emgHandlePublicGoodsList:[],
      //物资详情
      hiddenGoodsDetail:true,
      emgGoods:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
          eventId:options.eventId,
          title:options.title
      });
      this.getEventContent();
  },
    getEventContent:function () {
        let that = this;
        let header= {
            'Cookie': wx.getStorageSync("sessionid"), //读取cookie
            'content-type': 'application/json'
        };
        this.setData({
            id:'',
            attentionItem:'',
            actionList:[],
            emgHandlePublicGoodsList:[],
            imgList:[]
        });
        wx.showLoading()
        wx.request({
            url: app.globalData.baseUrl + '/safe/emgHandlePublic/find',
            header: header,
            data: {eventId: this.data.eventId},
            method: 'post',
            success: function (res) {
                let tempList = res.data.data.list[0].emgHandleListPublics;
                tempList.forEach(function (item) {
                    item.checkFlag=item.status>0;
                });
                that.setData({
                    id:res.data.data.list[0].id,
                    attentionItem:res.data.data.list[0].attentionItem,
                    remark:res.data.data.list[0].remark,
                    actionList:tempList,
                    emgHandlePublicGoodsList:res.data.data.list[0].emgHandlePublicGoodsList
                });
                //关闭加载
                wx.hideLoading()
            },
            fail: function (err) {
                wx.showToast({
                    title: '获取数据失败',
                    icon: 'none',
                })
                //关闭加载
                wx.hideLoading()
            }
        });
        wx.request({
            url: app.globalData.baseUrl + '/safe/file/find',
            header: { 'Cookie': wx.getStorageSync("sessionid"), 'content-type': 'application/x-www-form-urlencoded'},
            data: {contentId: this.data.eventId,contentType:3},
            method: 'post',
            success: function (res) {
                let tempList=res.data.data;
                let bigImgList=[];
                tempList.forEach(function (item) {
                    item.imgUrl=app.globalData.baseUrl + '/safe/file/download?fId=' + item.fId;
                    bigImgList.push(item.imgUrl + '&percentage=1')
                });
                that.setData({
                    imgList:tempList,
                    bigImgList:bigImgList
                })
            },
            fail: function (err) {
            }
        });
    },
    //预览图片
    handleImagePreview:function (e) {
        const idx = e.target.dataset.idx
        const images = this.data.bigImgList
        wx.previewImage({
            current: images[idx],  //当前预览的图片
            urls: images,  //所有要预览的图片
        })
    },
    //返回
    goBackClick:function () {
        wx.navigateBack({
            delta: 1
        })
    }


})